/**
**************************************************************************************
*Founder Effect                                                                      *
*Copyright (C) 2006-2007, 5d Studios (www.5d-Studios.com)                            *
*                                                                                    *
*This library is free software; you can redistribute it and/or                       *
*modify it under the terms of the GNU Lesser General Public                          *
*License as published by the Free Software Foundation; either                        *
*version 2.1 of the License, or (at your option) any later version.                  *
*                                                                                    *
*This library is distributed in the hope that it will be useful,                     *
*but WITHOUT ANY WARRANTY; without even the implied warranty of                      *
*MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU                   *
*Lesser General Public License for more details.                                     *
*                                                                                    *
*You should have received a copy of the GNU Lesser General Public                    *
*License along with this library; if not, write to the Free Software                 *
*Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA      *
**************************************************************************************
*/
#include "StdAfx.h"
#include "MPanel.h"

namespace gui {

//MPanel::MPanel(void)
//{
//}
//
//MPanel::~MPanel(void)
//{
//
//}
/** Update this component */
void MPanel::Update( float dt )
{
    m_animation.Update( dt );

    // now draw all sub components
    gui::Component::Update( dt );
}

/** Render the panel */
void MPanel::Render( IRender* r )
{
    Vector3f bg = GetBackgroundColor();
    int width = GetWidth();
    int height = GetHeight();
    // set background color
    r->SetColor( bg.GetX(), bg.GetY(), bg.GetZ(), GetAlpha() );

    Vector2f pos = GetLocation();
    r->FillRect( pos.x, pos.y, width, height );

    if ( !m_images.empty() )
    {
        Image currentImage = m_images[ m_animation.GetFrame()-1 ];
        if ( currentImage.width > width ) width = currentImage.width;
        if ( currentImage.height > height ) height = currentImage.height;
        // draw the image
        r->DrawImage( &currentImage , pos.x, pos.y, width, height  );
    }
    // now draw all sub components
    gui::Component::Render( r );
}

};